package com.wash.shoes.util;

import com.wash.shoes.entity.RegionTransactionDetailPo;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;

/**
 * @author wangxy
 * @version DateUtils.java, v 0.1 2025/3/17 22:13 wangxy
 */
public class DateUtils {

    public static boolean isCreatedTimeGreaterThan7Days(RegionTransactionDetailPo po) {
        if (po == null || po.getCreateTime() == null) {
            return true;
        }

        LocalDateTime createTime = convertDateToLocalDateTime(po.getCreateTime());
        LocalDateTime now = LocalDateTime.now();

        return ChronoUnit.DAYS.between(createTime, now) > 7;
    }

    public static LocalDateTime convertDateToLocalDateTime(Date date) {
        return Instant.ofEpochMilli(date.getTime())
                .atZone(ZoneId.systemDefault())
                .toLocalDateTime();
    }
}
